import DS from 'ember-data';
import Ember from 'ember';
import BaseModel from './base-model';
/*客户*/
var Customer = BaseModel.extend({
  pathConfiger: Ember.inject.service("path-configer"),
  dateService: Ember.inject.service("date-service"),
  code: DS.attr('string'),
  desc: DS.attr('string'),
  name: DS.attr('string'),//姓名
  enterprise: DS.attr('string'),//公司名称
  phone: DS.attr('number'),//电话号码
  email: DS.attr('string'),//邮箱
  weixin:DS.attr('string'),//微信号
  address:DS.attr('string'),//地址
  mark: DS.attr('number'),//标志,1呼入2呼出
  birthday: DS.attr('number'),//生日
  age: DS.attr('number'),//年龄
  qq: DS.attr('string'),//qq
  position: DS.attr('string'),//职位
  createTime: DS.attr('number'),//创建时间
  updateTime: DS.attr('number'),//更新时间
  isAllocated: DS.attr('number'),//是否已分配  0 ：未分配    1：已分配
  extendInfo: DS.attr('string'),//扩展信息
  remark: DS.attr('string'),//备注
  discountRate: DS.attr('string'),//折扣率
  //2016\11\8customer号新添加字段
  bed: DS.belongsTo('bed'),//所属床位
  lastUpdateUser:DS.belongsTo('user'),

  //crateUser:DS.belongsTo('user'),
  sex: DS.belongsTo('dicttype'),//性别,1男2女
  //staff:DS.belongsTo('dicttype'),//服务护工
  nursingGrade:DS.belongsTo('dicttype'),//护理等级（护理级别）
  incomeType:DS.belongsTo('dicttype'),//入住类型
  expenceType:DS.belongsTo('dicttype'),//付费类型
  diningStandard:DS.belongsTo('dicttypetenant'),//餐饮标准
  customerStatus:DS.belongsTo('dicttype'),//入住状态
  selfCareAbility:DS.belongsTo('dicttype'),//自理能力
  bloodType:DS.belongsTo('dicttype'),//血型
  religion:DS.belongsTo('dicttype'),//宗教信仰
  maritalStatus:DS.belongsTo('dicttype'),//婚姻状况
  educationLevel:DS.belongsTo('dicttype'),//学历（文化程度）
  cardCode:DS.attr("string"),//身份证号
  nationality:DS.belongsTo('dicttype'),//民族
  customerNative:DS.belongsTo('dicttype'),//籍贯
  customerPS:DS.attr("string"),//身体情况
  customerCustom:DS.attr("string"),//生活习惯
  customerCharacter:DS.attr("string"),//性格特点
  customerHobby:DS.attr("string"),//个人爱好
  customerDiet:DS.attr("string"),//饮食偏好
  guardianFirstName:DS.attr("string"),//第一监护人姓名
  guardianFirstContact:DS.attr("string"),//第一监护人电话
  guardianFirstGener:DS.belongsTo('dicttype'),//第一监护人性别
  firstRelation:DS.belongsTo("dicttype"),//第一监护人与老人关系
  guardianFirstCardCode:DS.attr("string"),//第一监护人身份证
  guardianFirstWork:DS.attr("string"),//第一监护人工作单位
  guardianFirstAddress:DS.attr("string"),//第一监护人地址
  contractNO:DS.attr("string"),//合同编号  关联合同表
  checkInDate:DS.attr("number"),//入住开始时间
  checkOutDate:DS.attr("number"),//入住结束时间（退房时间）
  actualDeposit:DS.attr("string"),//保证金
  referencePrice:DS.attr("string"),//参考价格
  actualPrice:DS.attr("string"),//实际价格
  headImg: DS.attr('string'), //头像文件名（头像地址）
  staffs:DS.hasMany('user',{inverse:'customers'}),//老人所对应的护工列表

  computeSex:Ember.computed("cardCode",function(){
    var cardCode=this.get("cardCode");
    if (parseInt(cardCode.substr(16, 1)) % 2 == 1) {
      return "男";
    }else {
      return "女";
    }
  }),
  // cardCodeObs: function(){
  //   var cardCode=this.get("cardCode");
  //   console.log("cardCode is",cardCode);
  //   var dateStr = cardCode.substring(6, 10) + "-" + cardCode.substring(10, 12) + "-" + cardCode.substring(12, 14);
  //   console.log("dateStr is",dateStr);
  //   var birthday = this.get("dateService").timeStringToTimestamp(dateStr);
  //   console.log("birthday isis",birthday);
  //   this.set("birthday",birthday);
  //
  // }.observes("cardCode"),

  computeBirthday:Ember.computed("cardCode",function(){
    var cardCode=this.get("cardCode");
    return cardCode.substring(6, 10) + "-" + cardCode.substring(10, 12) + "-" + cardCode.substring(12, 14);
  }),
  staffList:new Ember.A(),
  realActualDeposit:Ember.computed("actualDeposit",function(){
    var actualDeposit=this.get("actualDeposit");
    if(!actualDeposit){
      return ""+"元";
    }
    return actualDeposit+"元";
  }),
  realReferencePrice:Ember.computed("referencePrice",function(){
    var referencePrice=this.get("referencePrice");
    if(!referencePrice){
      return ""+"元/月";
    }
    return referencePrice+"元/月";
  }),
  realActualPrice:Ember.computed("actualPrice",function(){
    var actualPrice=this.get("actualPrice");
    if(!actualPrice){
      return ""+"元/月";
    }
    return actualPrice+"元/月";
  }),
  staffListString:Ember.computed("staffList",function(){
    var str = "";
    this.get("staffList").forEach(function(staff){
      str = str + "," + staff.get("name");
    });
    if(str.length===0){
      str = "无";
    }else{
      str = str.substring(0,str.length-1);
    }
    return str;
  }),
  avatarUrl: Ember.computed('headImg',function(){
    var avatar = this.get('headImg');
    if(!avatar){
      avatar = "anonymous.png";
      return this.get("pathConfiger").getAvatarLocalPath(avatar);
    }
    return this.get("pathConfiger").getAvatarRemotePath(avatar);
  }),
  markStr: Ember.computed('mark',function(){
    var mark = this.get('mark');
    if(mark===1){
      return "半失能";
    }
    if(mark===2){
      return "全失能";
    }
    return "健康";
  }),
  phoneHidden:Ember.computed('phone',function(){
    var phone = this.get('phone');
    if(phone) {
      console.log('fasgwefaefrcgfeasv rf',phone);
      var phoneStr = phone.toString();
      phoneStr = phoneStr.substring(0,3)+'****'+phoneStr.substring(7);
      return phoneStr;
    }
    return ;
  }),
  birthdayShow: Ember.computed('birthday',function() {
    var dateOri = this.get("birthday");
    if(!dateOri) {
      return '';
    }
    else {
      var date = new Date(dateOri*1000);
      date = date.getFullYear()+"-"+this.toDbl(date.getMonth()+1)+"-"+this.toDbl(date.getDate());
      return date;
    }
  }),
  createTimeShow: Ember.computed('createTime',function() {
    var dateOri = this.get("createTime");
    var date = new Date(dateOri*1000);
    if(date === 'Invalid Date'){
      date = '';
    }
    else{
      date = date.getFullYear()+"-"+this.toDbl(date.getMonth()+1)+"-"+this.toDbl(date.getDate())+" "+this.toDbl(date.getHours())+":"+this.toDbl(date.getMinutes());
    }
    return date;
  }),
  updateTimeShow: Ember.computed('updateTime',function() {
    var dateOri = this.get("updateTime");
    var date = new Date(dateOri*1000);
    if(date === 'Invalid Date'){
      date = '';
    }
    else{
      date = date.getFullYear()+"-"+this.toDbl(date.getMonth()+1)+"-"+this.toDbl(date.getDate())+" "+this.toDbl(date.getHours())+":"+this.toDbl(date.getMinutes());
    }
    return date;
  }),
  familyRelation:Ember.computed("guardianFirstName,guardianFirstContact",function(){
    var name=this.get("guardianFirstName");
    var phone=this.get("guardianFirstContact");
    return name+"<"+phone+">";
  }),
  birthdayTime:Ember.computed("birthday",function(){
    var birthday=this.get("birthday");
    if(!birthday){
      return null;
    }
    return this.get("dateService").timestampToTime(birthday);
  }),
  checkInDateTime :Ember.computed("checkInDate",function(){
    var checkInDate=this.get("checkInDate");
    return this.get("dateService").timestampToTime(checkInDate);
  }),
  checkOutDateTime:Ember.computed("checkOutDate",function(){
      var checkOutDate=this.get("checkOutDate");
      return this.get("dateService").timestampToTime(checkOutDate);
  }),

  birthdayString:Ember.computed("birthday",function(){
    var birthday=this.get("birthday");
    return this.get("dateService").formatDate(birthday,"yyyy-MM-dd");

  }),
  checkInDateString:Ember.computed("checkInDate",function(){
    var checkInDate=this.get("checkInDate");
    return this.get("dateService").formatDate(checkInDate,"yyyy-MM-dd");

  }),
  checkOutDateString:Ember.computed("checkOutDate",function(){
    var checkOutDate=this.get("checkOutDate");
    return this.get("dateService").formatDate(checkOutDate,"yyyy-MM-dd");

  }),
  toDbl: function(value) {
    if(value<10)
    {
      return '0'+value;
    }
    else
    {
      return ''+value;
    }
  }
});
export default Customer;
